<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>租赁合同</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
<link rel="stylesheet" href="css/apaltment.css">
<link rel="stylesheet" href="css/jquery.sPage.css">
<link rel="stylesheet" href="css/jquery.sPage.green.css">
<link rel="stylesheet" href="css/jquery.sPage.red.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.loading{
	width:200px;
	margin-left:45%;
}
    	.num{
            height: 50px;
    		line-height: 50px;
    		text-align: center;
    	}
    	.demo{
            margin-bottom: 20px;
            text-align: center;
        }
        
        /*租户详情页*/
		.xiangqing{
			width:100%;
			height:40px;
			background:floralwhite;
			margin:0 auto;
		}
        .modal-header{
			background:skyblue !important;
			color:saddlebrown !important;
		}
		.xiangqing:nth-child(2n){
			background:white !important;
		}
		.xiangqing div{
			height:40px;
			font-size:16px;
			line-height:40px;
		}
		.xiang_left{
			text-align:center;
			width:30% !important;
			float:left !important;
		}
		.xiang_right{
			text-align:left;
			width:70% !important;
			float:right !important;
		}
		.choose{
			width:120px;
			height:30px;
			border:1px solid silver;
			color:slategray;
		}
    </style>
</head>
<body>
<div class="search">
        <form>
        <span onclick="chooseDongtai()" class="btn btn-primary" style="margin-right:10px" data-toggle='modal' data-target='#add'>添加</span>
            <label>
                <span>合同签署人：</span>
                <input class="contractSigner" type="text" placeholder="输入合同签署人">
            </label>
            <label>
                <span>合同状态：</span>
                <select class="contractState">
                    <option value="">--请选择--</option>
                    <option value="已生效">已生效</option>
                    <option value="已失效">已失效</option>
                </select>
            </label>
            <label>
                <span>合同期数：</span>
                <input class="contractCount" type="text" placeholder="输入合同期数">
            </label>
            <button type="button" style="margin-left: 25px" class="btn btn-primary SearchByContract">查询</button>
        </form>
    </div>
<table class="table table-bordered" style="margin-top: 20px;">
    
    <thead>
        <tr>
            <th>合同号</th>
            <th>签署日期</th>
            <th>结束日期</th>
            <th>合同期数</th>
            <th>付款方式</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody id="msg">
        
    </tbody>
</table>
<img class="noneData" style="display:none" src="images/dataNone.png">
<img class="loading" src="images/loading.gif">
<div id="myPage" class="demo"></div>

<!-- 详情 -->
<div class="modal fade" id="detail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        详情信息
                    </h4>
                </div>
                <div class="modal-body" style="overflow:hidden">
					<div class="xiangqing">
						<div class="xiang_left">合同期限：</div>
   						<div class="xiang_right c_alltime"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">签署日期：</div>
   						<div class="xiang_right c_begintime"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">结束日期：</div>
   						<div class="xiang_right c_endtime"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">租赁总额（元）：</div>
   						<div class="xiang_right c_total"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">付款方式：</div>
   						<div class="xiang_right c_mode"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">押金：</div>
   						<div class="xiang_right c_deposit"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">付款期数：</div>
   						<div class="xiang_right c_count"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">合同签署人：</div>
   						<div class="xiang_right c_Signer"></div>
					</div>
					<div class="xiangqing">
						<div class="xiang_left">合同状态：</div>
   						<div class="xiang_right c_state"></div>
					</div>
					
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div> 

<!-- 修改信息 -->
<div class="modal fade" id="update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        修改信息
                    </h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                    	<input type="text" id="c_id" name="c_id" hidden>
                    	<input type="text" id="c_num" name="c_num" hidden>
                    	<input type="text" id="h_id" name="h_id" hidden>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同日期：</label>
                            <div class="col-sm-8">
                                <input type="text" id="c_alltime" name="c_alltime" class="form-control" placeholder="请输入合同日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">签署日期：</label>
                            <div class="col-sm-8">
                                <input type="date" style="line-height:23px" id="c_begintime" name="c_begintime" class="form-control" placeholder="请输入签署日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">结束日期：</label>
                            <div class="col-sm-8">
                                <input type="date" style="line-height:23px" id="c_endtime" name="c_endtime" class="form-control" placeholder="请输入结束日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">租赁总额(元)：</label>
                            <div class="col-sm-8">
                                <input type="text" id="c_total" name="c_total" class="form-control" placeholder="请输入租赁总额">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">付款方式：</label>
                            <div class="col-sm-8">
                                <select id="c_mode" name="c_mode" class="form-control">
                                	<option>--请选择--</option>
                                	<option value="月付">月付</option>
                                	<option value="半年付">半年付</option>
                                	<option value="年付">年付</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">押金(元)：</label>
                            <div class="col-sm-8">
                                <input type="text" id="c_deposit" name="c_deposit" class="form-control " placeholder="请输入押金">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">付款期数：</label>
                            <div class="col-sm-8">
                                <input type="text" id="c_count" name="c_count" class="form-control" placeholder="请输入付款期数">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同签署人：</label>
                            <div class="col-sm-8">
                                <input type="text" id="c_signer" name="c_signer" class="form-control" placeholder="请输入签署人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同状态：</label>
                            <div class="col-sm-8">
                                <select id="c_state" name="c_state" class="form-control">
                                	<option>--请选择--</option>
                                	<option value="已生效">已生效</option>
                                	<option value="已失效">已失效</option>
                                </select>
                            </div>
                        </div>
                        
                   
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" id="submit" class="btn btn-primary">
                        提交更改
                    </button>
                </div>
                 </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div> 
    
    <!-- 添加信息 -->
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        添加信息
                    </h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                    	<input type="text" id="c_id" name="c_id" hidden>
                    	<div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同编号：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control hetonghao" placeholder="请输入合同编号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同期限：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control alltime" placeholder="请输入合同日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">签署日期：</label>
                            <div class="col-sm-8">
                                <input type="date" style="line-height:23px" class="form-control begintime" placeholder="请输入签署日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">结束日期：</label>
                            <div class="col-sm-8">
                                <input type="date" style="line-height:23px" class="form-control endtime" placeholder="请输入结束日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">租赁总额(元)：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control total" placeholder="请输入租赁总额">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">付款方式：</label>
                            <div class="col-sm-8">
                                <select class="form-control mode">
                                	<option>--请选择--</option>
                                	<option value="月付">月付</option>
                                	<option value="半年付">半年付</option>
                                	<option value="年付">年付</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">押金(元)：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control deposit" placeholder="请输入押金">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">详细地址：</label>
                            <div class="col-sm-8">
                                <select class="choose chooseDiqu">
                                	<option value="">--请选择--</option>
                                </select>
                                <select class="choose chooseXiaoqu">
                                	<option value="">--请选择--</option>
                                </select>
                                <select class="choose chooseDanyuan">
                                	<option value="">--请选择--</option>
                                </select>
								
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">房间号：</label>
                            <div class="col-sm-8">
                                <select  class="form-control chooseFangjian">
                                	<option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">付款期数：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control count" placeholder="请输入付款期数">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同签署人：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control signer" placeholder="请输入签署人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="firstname" class="col-sm-4 control-label">合同状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control state">
                                	<option>--请选择--</option>
                                	<option value="已生效">已生效</option>
                                	<option value="已失效">已失效</option>
                                </select>
                            </div>
                        </div>
                        
                   
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" id="addTenants" class="btn btn-primary">
                        提交更改
                    </button>
                </div>
                 </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div> 
</body>
<script src="js/jquery.sPage.js"></script>
<script>
$(function(){
    ajaxPage(1);
});

function ajaxPage(page){
	$.ajax({
		url:"doGetAllContractServlet",
		dataType:"JSON",
		data:{pageIndex:page},
		success:function(data){
			console.log(data)
			$(".loading").css({"display":"none"})
			var msg = ""
			//var pages=data[0]
			var sum=0
			$.each(data,function(i,item){
				sum = item["sum"]
				msg += "<tr>"+
				"<td>"+item["c_num"]+"</td>"+
				"<td>"+item["c_begintime"]+"</td>"+
				"<td>"+item["c_endtime"]+"</td>"+
				"<td>"+item["c_count"]+"</td>"+
				"<td>"+item["c_mode"]+"</td>"+
				"<td>"+
					"<span onclick='updateContract("+item['c_id']+")' class='btn btn-info' data-toggle='modal' data-target='#update'>修改</span>"+
					"<span onclick='updateContract("+item['c_id']+")' class='btn btn-success' data-toggle='modal' data-target='#detail'>详情</span>"+
					"<span onclick='deleteById("+item['c_id']+")' class='btn btn-danger'>删除</span>"+
				"</td>"+
			"</tr>"
			})
			$("#msg").html(msg)
			
			$("#myPage").unbind();
			$("#myPage").sPage({
		        page:page,//当前页码，必填
		        total:sum,//数据总条数，必填
		        pageSize:10,//每页显示多少条数据，默认10条
		        showTotal:true,//是否显示总条数，默认关闭：false
		        totalTxt:"共{total}条",//数据总条数文字描述，{total}为占位符，默认"共{total}条"
		        noData: false,//没有数据时是否显示分页，默认false不显示，true显示第一页
		        showSkip:false,//是否显示跳页，默认关闭：false
		        showPN:true,//是否显示上下翻页，默认开启：true
		        prevPage:"上一页",//上翻页文字描述，默认“上一页”
		        nextPage:"下一页",//下翻页文字描述，默认“下一页”
		        fastForward: 5,//快进快退页数，默认0表示不开启快进快退
		        backFun:function(page){
		        	//点击分页按钮回调函数，返回当前页码
		            ajaxPage(page)
		            $("#msg").html("")
		            $(".loading").css({"display":"block"})
		        }
		    });
		},
		error:function(err){
			
		}
	})
}

//删除合同信息
function deleteById(c_id){
	if(confirm("确定删除吗？")){
		$.ajax({
			url:"doDeleteServlet", 
			dataType:"JSON",
			data:{c_id:c_id},
			success:function(data){
				alert("删除成功")
				window.location.reload()
			},
		})
	}else{
		return;
	}
}
//详情页
function updateContract(c_id){
	$.ajax({
		url:"doGetAllByScnoServlet", 
		dataType:"JSON",
		data:{c_id:c_id},
		success:function(data){
			$("#c_id").val(data.c_id)
			$("#c_num").val(data.c_num)
			$("#h_id").val(data.h_id)
			$("#c_alltime").val(data.c_alltime)
			$("#c_begintime").val(data.c_begintime)
			$("#c_endtime").val(data.c_endtime)
			$("#c_total").val(data.c_total)
			$("#c_mode").val(data.c_mode)
			$("#c_deposit").val(data.c_deposit)
			$("#c_count").val(data.c_count)
			$("#c_signer").val(data.c_signer)
			$("#c_state").val(data.c_state)
			
			$(".c_alltime").html(data.c_alltime)
			$(".c_begintime").html(data.c_begintime)
			$(".c_endtime").html(data.c_endtime)
			$(".c_total").html(data.c_total+"元")
			$(".c_mode").html(data.c_mode)
			$(".c_deposit").html(data.c_deposit+"元")
			$(".c_count").html(data.c_count)
			$(".c_signer").html(data.c_signer)
			$(".c_state").html(data.c_state)
		},
	})
}

//提交修改后的数据
$('#submit').click(function() {
	$("#c_id").val()
    $.ajax({
    	url:"doUpdateServlet", 
		dataType:"JSON",
		type:"get",
		data:{
			"c_id":$("#c_id").val(),
			"c_num":$("#c_num").val(),
			"h_id":$("#h_id").val(),
			"c_alltime":$("#c_alltime").val(),
			"c_begintime":$("#c_begintime").val(),
			"c_endtime":$("#c_endtime").val(),
			"c_total":$("#c_total").val(),
			"c_mode":$("#c_mode").val(),
			"c_deposit":$("#c_deposit").val(),
			"c_signer":$("#c_signer").val(),
			"c_state":$("#c_state").val(),
			"c_count":$("#c_count").val()
		},
		success:function(data){
			alert("修改成功")
			window.location.reload()
		}
    })
  })
  
  
  //按条件查询
  $(".SearchByContract").click(function(){
	  $("#msg").html("")
	  $(".loading").css({"display":"block"})
	  $(".noneData").css({display:"none"})
	  searchByCon(1)
  })
  
  function searchByCon(page){
	  $.ajax({
		  url:"doSearchServlet", 
			dataType:"JSON",
			type:"get",
			data:{
				"c_signer":$(".contractSigner").val(),
				"c_count":$(".contractCount").val(),
				"c_state":$(".contractState").val(),
				"page":page
			},
			success:function(data){
				$(".loading").css({"display":"none"})
				var msg = ""
				//var pages=data[0]
				var sum=0
				$.each(data,function(i,item){
					sum = item["sum"]
					msg += "<tr>"+
					"<td>"+item["c_num"]+"</td>"+
					"<td>"+item["c_begintime"]+"</td>"+
					"<td>"+item["c_endtime"]+"</td>"+
					"<td>"+item["c_count"]+"</td>"+
					"<td>"+item["c_mode"]+"</td>"+
					"<td>"+
						"<span onclick='updateContract("+item['c_id']+")' class='btn btn-info' data-toggle='modal' data-target='#update'>修改</span>"+
						"<span onclick='updateContract("+item['c_id']+")' class='btn btn-success' data-toggle='modal' data-target='#detail'>详情</span>"+
						"<span onclick='deleteById("+item['c_id']+")' class='btn btn-danger'>删除</span>"+
					"</td>"+
				"</tr>"
				})
				$("#msg").html(msg)
				if(sum==0){
					$(".noneData").css({display:"block"})
				}
				$("#myPage").unbind();
				$("#myPage").sPage({
			        page:page,//当前页码，必填
			        total:sum,//数据总条数，必填
			        pageSize:10,//每页显示多少条数据，默认10条
			        showTotal:true,//是否显示总条数，默认关闭：false
			        totalTxt:"共{total}条",//数据总条数文字描述，{total}为占位符，默认"共{total}条"
			        noData: false,//没有数据时是否显示分页，默认false不显示，true显示第一页
			        showSkip:false,//是否显示跳页，默认关闭：false
			        showPN:true,//是否显示上下翻页，默认开启：true
			        prevPage:"上一页",//上翻页文字描述，默认“上一页”
			        nextPage:"下一页",//下翻页文字描述，默认“下一页”
			        fastForward: 5,//快进快退页数，默认0表示不开启快进快退
			        backFun:function(page){
			        	//点击分页按钮回调函数，返回当前页码
			            searchByCon(page)
			            $("#msg").html("")
			            $(".loading").css({"display":"block"})
			        }
			    });
				
			},
	  })
  }
  
//动态选择地区、小区、单元号、房间号
function chooseDongtai(){
	$.ajax({
		url:"TenantZuFang1", 
		dataType:"JSON",
		type:"post",
		success:function(data){
			var options=""
				for(var i=0;i<data.length;i++){
					options += "<option value="+data[i]+">"+data[i]+"</option>"
				}
			$(".chooseDiqu").html(options)
			$.ajax({
				url:"TenantZuFang2", 
				dataType:"JSON",
				type:"post",
				data:{"h_region":$(".chooseDiqu").val()},
				success:function(data){
					var options=""
						for(var i=0;i<data.length;i++){
							options += "<option value="+data[i]+">"+data[i]+"</option>"
						}
					$(".chooseXiaoqu").html(options)
					$.ajax({
						url:"TenantZuFang3", 
						dataType:"JSON",
						type:"post",
						data:{
							"h_region":$(".chooseDiqu").val(),
							"h_village":$(".chooseXiaoqu").val()
						},
						success:function(data){
							var options=""
								for(var i=0;i<data.length;i++){
									options += "<option value="+data[i]+">"+data[i]+"</option>"
								}
							$(".chooseDanyuan").html(options)
							$.ajax({
								url:"TenantZuFang4", 
								dataType:"JSON",
								type:"post",
								data:{
									"h_region":$(".chooseDiqu").val(),
									"h_village":$(".chooseXiaoqu").val(),
									"h_unit":$(".chooseDanyuan").val()
								},
								success:function(data){
									var options=""
										for(var i=0;i<data.length;i++){
											options += "<option value="+data[i]+">"+data[i]+"</option>"
										}
									$(".chooseFangjian").html(options)
								},
							})
						}
					})
				}
			})
			
		},
	})
}
//改变状态
$(".chooseDiqu").change(function(){
	$.ajax({
		url:"TenantZuFang2", 
		dataType:"JSON",
		type:"post",
		data:{"h_region":$(".chooseDiqu").val()},
		success:function(data){
			var options=""
				for(var i=0;i<data.length;i++){
					options += "<option value="+data[i]+">"+data[i]+"</option>"
				}
			$(".chooseXiaoqu").html(options)
			$.ajax({
				url:"TenantZuFang3", 
				dataType:"JSON",
				type:"post",
				data:{
					"h_region":$(".chooseDiqu").val(),
					"h_village":$(".chooseXiaoqu").val()
				},
				success:function(data){
					var options=""
						for(var i=0;i<data.length;i++){
							options += "<option value="+data[i]+">"+data[i]+"</option>"
						}
					$(".chooseDanyuan").html(options)
					$.ajax({
						url:"TenantZuFang4", 
						dataType:"JSON",
						type:"post",
						data:{
							"h_region":$(".chooseDiqu").val(),
							"h_village":$(".chooseXiaoqu").val(),
							"h_unit":$(".chooseDanyuan").val()
						},
						success:function(data){
							var options=""
								for(var i=0;i<data.length;i++){
									options += "<option value="+data[i]+">"+data[i]+"</option>"
								}
							$(".chooseFangjian").html(options)
						}
					})
				}
			})
		}
	})
})
$(".chooseXiaoqu").change(function(){
	$.ajax({
		url:"TenantZuFang3", 
		dataType:"JSON",
		type:"post",
		data:{
			"h_region":$(".chooseDiqu").val(),
			"h_village":$(".chooseXiaoqu").val()
		},
		success:function(data){
			var options=""
				for(var i=0;i<data.length;i++){
					options += "<option value="+data[i]+">"+data[i]+"</option>"
				}
			$(".chooseDanyuan").html(options)
			$.ajax({
				url:"TenantZuFang4", 
				dataType:"JSON",
				type:"post",
				data:{
					"h_region":$(".chooseDiqu").val(),
					"h_village":$(".chooseXiaoqu").val(),
					"h_unit":$(".chooseDanyuan").val()
				},
				success:function(data){
					var options=""
						for(var i=0;i<data.length;i++){
							options += "<option value="+data[i]+">"+data[i]+"</option>"
						}
					$(".chooseFangjian").html(options)
				}
			})
		}
	})
})
$(".chooseDanyuan").change(function(){
	$.ajax({
		url:"TenantZuFang4", 
		dataType:"JSON",
		type:"post",
		data:{
			"h_region":$(".chooseDiqu").val(),
			"h_village":$(".chooseXiaoqu").val(),
			"h_unit":$(".chooseDanyuan").val()
		},
		success:function(data){
			var options=""
				for(var i=0;i<data.length;i++){
					options += "<option value="+data[i]+">"+data[i]+"</option>"
				}
			$(".chooseFangjian").html(options)
		}
	})
})


//添加数据
$("#addTenants").click(function(){
	$.ajax({
		url:"getHidByRVURServlet", 
		dataType:"JSON",
		data:{ 
			"h_region":$(".chooseDiqu").val(),
			"h_village":$(".chooseXiaoqu").val(),
			"h_unit":$(".chooseDanyuan").val(),
			"h_roomnum":$(".chooseFangjian").val(),
		},
		success:function(data){
			$.ajax({
				url:"doAddServlet", 
				dataType:"JSON",
				data:{ 
					"h_id":data,
					"c_num":$(".hetonghao").val(),
					"c_alltime":$(".alltime").val(),
					"c_begintime":$(".begintime").val(),
					"c_endtime":$(".endtime").val(),
					"c_total":$(".total").val(),
					"c_mode":$(".mode").val(),
					"c_deposit":$(".deposit").val(),
					"c_count":$(".count").val(),
					"c_signer":$(".signer").val(),
					"c_state":$(".state").val(),
				},
				success:function(data){
					if(data){
						alert("添加成功！")
						window.location.reload()
					}else{
						alert("该合同编号已存在！")
					}
					
				}
			})
		}
	})	
})
 </script>
</html>